package com.ECUT.javaSE.day2;

import java.util.Scanner;

public class practice5 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int productID;
        int count;
        int amount1 = 0, amount2 = 0, amount3 = 0;
        int total;
        float discount;
        double pay;
        int gear = 0;
        String isContinue;

        bar();

        do {
            System.out.println();
            System.out.println("请输入商品编号：");
            productID = sc.nextInt();
            System.out.println("请输入购买数量：");
            count = sc.nextInt();
            switch (productID) {
                case 1:
                    System.out.println("T恤￥245元\t" + "数量" + count + "\t总计：￥" + count * 245.00);
                    amount1 = count * 245;
                    break;
                case 2:
                    System.out.println("网球鞋￥570元\t" + "数量" + count + "\t总计：￥" + count * 570.00);
                    amount2 = count * 570;
                    break;
                case 3:
                    System.out.println("网球拍￥320元\t" + "数量" + count + "\t总计：￥" + count * 320.00);
                    amount3 = count * 320;
                    break;
                default:
                    System.out.println("输入错误");
            }
            System.out.println("是否继续购买？（Y/N）");
            isContinue = sc.next();
        } while (!"N".equals(isContinue)&&!"n".equals(isContinue));
        //计算总金额
        total = amount1 + amount2 + amount3;
        //计算折扣
        discount = compute(total);
        System.out.println("折扣是" + discount);
        System.out.println("应付金额为：");
        System.out.println(total * discount);
        System.out.println("实付金额为：");
        pay = sc.nextDouble();
        if (total * discount > pay) {
            System.out.println("您的钱不够");
        }else {
            System.out.println("找钱：" + (pay - (amount1 + amount2 + amount3) * discount));
        }

    }
    private static void bar() {
        System.out.println("**********************************************");
        System.out.println("请选择购买的商品编号：");
        System.out.println("1.T恤\t2.网球鞋\t\t3.网球拍");
        System.out.println("**********************************************");
    }

    private static float compute(int total) {
        float discount;
        //设置三档折扣，总金额大于3000打5折，大于2000打6折，大于1000打8折
        if (total > 3000) {
            discount = 0.8f;
        } else if (total > 2000) {
            discount = 0.9f;
        } else if (total > 1000) {
            discount = 0.95f;
        } else {
            discount = 1.0f;
        }
        return discount;
    }
}
